﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Repository;
using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.AgentEditor
{

	/// <summary>
	/// Declaration of CachedData class
	/// Singleton pattern class for storing supporting data
	/// </summary>
	public class CachedData : CachedDataBase
	{

		/////////////////////////////////////////////////////////////
		// Enumerations

		/////////////////////////////////////////////////////////////
		// Attributes

		public static CachedData Singleton
		{
			get { return m_SingletonBase as CachedData; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		static CachedData()
		{

			// Create the single instance
			new CachedData();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		public void AddIncoming(AgentEditorSupportData supportData)
		{

			// Process data returned from server

			// Call base-class function
			base.AddIncoming(
				supportData.CurrentUser,
				supportData.CountryDictionary,
				supportData.ContactPositions,
				supportData.ContactTitles,
				supportData.ContactCounties,
				supportData.BankNames
			);

		}

		/////////////////////////////////////////////////////////////
		// Static Operations - Fake data used during testing

#if USEFAKEDATA
		public static AgentEditorSupportData GetDummySupportingData()
		{

			// Declare return variable
			AgentEditorSupportData Ftmp = new AgentEditorSupportData();

			// Load the dictionary
			Ftmp.CountryDictionary = new Dictionary<string, string>();
			Ftmp.CountryDictionary.Add("UK", "United Kingdom");
			Ftmp.CountryDictionary.Add("RS", "Russia");
			Ftmp.CountryDictionary.Add("FR", "France");

			// Load the re-usable strings
			Ftmp.ContactTitles = new ObservableCollection<string>();
			Ftmp.ContactTitles.Add("Mr.");
			Ftmp.ContactTitles.Add("Mrs.");
			Ftmp.ContactTitles.Add("Dr.");
			Ftmp.ContactPositions = new ObservableCollection<string>();
			Ftmp.ContactPositions.Add("CEO");
			Ftmp.ContactPositions.Add("Director");
			Ftmp.ContactCounties = new ObservableCollection<string>();
			Ftmp.ContactCounties.Add("Berks");
			Ftmp.ContactCounties.Add("Surrey");
			Ftmp.ContactCounties.Add("Kent");

			// Return variable
			return Ftmp;

		}
#endif // #if USEFAKEDATA

#if USEFAKEDATA
		public static AgentTransport GetDummyAgentTransport()
		{

			// Declare return variable
			AgentTransport Ftmp = new AgentTransport();
			Ftmp.CoverageCountryCodes = new System.Collections.ObjectModel.ObservableCollection<string>();
			Ftmp.Contacts = new System.Collections.ObjectModel.ObservableCollection<ContactTransport>();

			// Set agent details
			Ftmp.AgentId = 1;
			Ftmp.Name = "Andrew Agent";
			Ftmp.AgentType = (int)Definitions.eAgentType.Agent;
			Ftmp.CoverageCountryCodes = new System.Collections.ObjectModel.ObservableCollection<string>();
			Ftmp.CoverageCountryCodes.Add("UK");
			Ftmp.CoverageCountryCodes.Add("RS");
			Ftmp.SpecificCommissionRatePerc = 4.56;
			Ftmp.UseAccountCommissionRate = false;
			Ftmp.Website = "www.microsoft.com";
			Ftmp.Notes = "Bla bla bla";

			// Add contact
			ContactTransport newContact = new ContactTransport();
			newContact.AddressList = new System.Collections.ObjectModel.ObservableCollection<ContactAddressTransport>();
			newContact.PointList = new System.Collections.ObjectModel.ObservableCollection<ContactPointTransport>();
			newContact.ContactId = 1;
			newContact.Title = "Mr.";
			newContact.FirstName = "Toby";
			newContact.Initials = "X";
			newContact.Surname = "Stephens";
			newContact.Position = "CEO";
			newContact.Abbr = "Toz";
			newContact.AddressList.Add(new ContactAddressTransport()
			{
				AddressLineA = "Unit 45",
				AddressLineB = "Eastway Trading Estate",
				City = "Slough",
				County = "Berks",
				CountryCode = "UK"
			});
			newContact.AddressList.Add(new ContactAddressTransport()
			{
				AddressLineA = "8 Ledgers Court",
				AddressLineB = "Warfield",
				City = "Bracknell",
				County = "Berks",
				Postcode = "RG46 8SK",
				CountryCode = "UK"
			});
			newContact.PointList.Add(
				new ContactPointTransport() { ContactPointType = (int)Definitions.eContactPointType.Phone, Address = "01344 717 233" }
			);
			newContact.PointList.Add(
				new ContactPointTransport() { ContactPointType = (int)Definitions.eContactPointType.Mobile, Address = "07956 777162" }
			);
			newContact.PointList.Add(
				new ContactPointTransport() { ContactPointType = (int)Definitions.eContactPointType.Email, Address = "toby@hotmail.com" }
			);
			Ftmp.Contacts.Add(newContact);

			// Return variable
			return Ftmp;

		}
#endif // #if USEFAKEDATA

	}

}
